package com.spic.business.datamanagement.equipment.service.impl;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spic.business.datamanagement.equipment.entity.EquipmentInfo;
import com.spic.business.datamanagement.equipment.mapper.EquipmentInfoMapper;
import com.spic.business.datamanagement.equipment.service.IEquipmentInfoService;
import com.spic.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 数字矿山设备基本信息表 服务实现类
 * </p>
 *
 * @author 赵祥
 * @since 2022-11-19
 */
@Service
@DS("ods")
public class EquipmentInfoServiceImpl extends ServiceImpl<EquipmentInfoMapper, EquipmentInfo> implements IEquipmentInfoService {

    @Autowired
    private EquipmentInfoMapper equipmentInfoMapper;

    private static Map<String, String> equipmentTypeMap = new HashMap<>();

    static {
        equipmentTypeMap.put("1", "卡车");
        equipmentTypeMap.put("2", "挖机");
        equipmentTypeMap.put("3", "卸点");
        equipmentTypeMap.put("4", "钻机");
        equipmentTypeMap.put("9", "辅助设备");
    }

    @Override
    public List<EquipmentInfo> list(EquipmentInfo equipmentInfo) {
        QueryWrapper<EquipmentInfo> wrapper = new QueryWrapper(equipmentInfo);
        if(StringUtils.isNotEmpty(equipmentInfo.getEquipmentName())) {
            wrapper.like("equipment_name", equipmentInfo.getEquipmentName());
        }
        if(StringUtils.isNotEmpty(equipmentInfo.getEquipmentModel())) {
            wrapper.like("equipment_model", equipmentInfo.getEquipmentModel());
        }
        List<EquipmentInfo> equipmentInfos = equipmentInfoMapper.selectList(wrapper);
        equipmentInfos.stream().forEach(item -> {
            String equipmentType = item.getEquipmentType();
            equipmentType = equipmentTypeMap.get(equipmentType) == null ? equipmentType : equipmentTypeMap.get(equipmentType);
            item.setEquipmentType(equipmentType);
        });
        return equipmentInfos;
    }

}
